import axios from "axios";
// 引入mock
import '@/mock/home'

// 如果使用 mock.js 需要将 baseURL 的字符串修改为一个 /
const instance = axios.create({
    baseURL: "/",
    timeout: 60000,
});

instance.interceptors.request.use(
    function (config) {
        return config;
    },
    function (error) {
        return Promise.reject(error);
    }
);

instance.interceptors.response.use(
    function (response) {
        return response.data;
    },
    function (error) {
        return Promise.reject(error);
    }
);

export function ajax(options) {
    const { url, method = "GET", data = {} } = options;

    if (method.toUpperCase() === "GET") {
        return instance.get(url, { params: data });
    }

    if (method.toUpperCase() === "POST") {
        return instance.post(url, data);
    }
}
